package com.tgy.queue;

import com.tgy.heap.BinaryHeap;

import java.util.Comparator;

/**
 * @Author: tgy
 * @Date: 2020-10-12 11:31
 */
public class PriorityQueue<E> implements Queue<E>{

    private BinaryHeap<E> heap;

    public PriorityQueue() {

        this(null);
    }

    public PriorityQueue(Comparator<E> comparator) {

        heap = new BinaryHeap<>(comparator,null);
    }

    @Override
    public int size() {

        return heap.size();
    }

    @Override
    public boolean isEmpty() {

        return heap.isEmpty();
    }

    @Override
    public void enQueue(E element) {

        heap.add(element);
    }

    @Override
    public E deQueue() {

        return heap.remove();
    }

    @Override
    public E front() {
        return heap.get();
    }

    @Override
    public void clear() {

        heap.clear();
    }
}
